package com.huixue.cn.ztej.controller;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import com.huixue.cn.ztej.bean.Project;
import com.huixue.cn.ztej.bean.User;
import com.huixue.cn.ztej.dao.SysProjectMapper;
import com.huixue.cn.ztej.enums.RoleStatus;
import com.huixue.cn.ztej.utils.annotation.RequestMappingName;

@Controller
@RequestMapping(value = "/sys/sreport")
public class SysReportController  extends BaseController {
	
	/**
	 * <p>跳转到打印页面</p>
	 * @throws IOException 
	 */
	
	@Autowired
	private SysProjectMapper sysProjectMapper;
	
	
	@RequestMappingName(value = "跳转到添加页面")
	@RequestMapping(value = "/employ", method = RequestMethod.GET)
	public String employ(Model model,HttpServletRequest request,HttpServletResponse response) throws IOException {
		Map<String, Object> searchParams = new HashMap<String,Object>();
		User currentUser = (User)request.getSession().getAttribute("loginUser");

		//项目管理
		if(currentUser.getRoleId()!=null && currentUser.getRoleId().equals(RoleStatus.ROLE_8.getRoleId()+"")){
			searchParams.put("proId", currentUser.getProjectID());
		}
		
		java.util.List<Project> list = sysProjectMapper.findAll(searchParams);
		model.addAttribute("project", list);
		User user = (User)request.getSession().getAttribute("loginUser");
		model.addAttribute("user", user);		
		return "/report/employ";
	}
	
	
	@RequestMappingName(value = "跳转到添加页面")
	@RequestMapping(value = "/mech", method = RequestMethod.GET)
	public String mech(Model model,HttpServletRequest request,HttpServletResponse response) throws IOException {
		Map<String, Object> searchParams = new HashMap<String,Object>();
		User currentUser = (User)request.getSession().getAttribute("loginUser");

		//项目管理
		if(currentUser.getRoleId()!=null && currentUser.getRoleId().equals(RoleStatus.ROLE_8.getRoleId()+"")){
			searchParams.put("proId", currentUser.getProjectID());
		}
		
		java.util.List<Project> list = sysProjectMapper.findAll(searchParams);
		model.addAttribute("project", list);
		
		User user = (User)request.getSession().getAttribute("loginUser");
		model.addAttribute("user", user);	
		
		return "/report/mech";
	}
	
	@RequestMappingName(value = "跳转到添加页面")
	@RequestMapping(value = "/proemploy", method = RequestMethod.GET)
	public String proemploy(Model model,HttpServletRequest request,HttpServletResponse response) throws IOException {
		Map<String, Object> searchParams = new HashMap<String,Object>();
		User currentUser = (User)request.getSession().getAttribute("loginUser");

		//项目管理
		if(currentUser.getRoleId()!=null && currentUser.getRoleId().equals(RoleStatus.ROLE_8.getRoleId()+"")){
			searchParams.put("proId", currentUser.getProjectID());
		}
		
		/*java.util.List<Project> list = sysProjectMapper.findAll(searchParams);
		model.addAttribute("project", list);*/
		User user = (User)request.getSession().getAttribute("loginUser");
		model.addAttribute("user", user);		
		return "/report/proemploy";
	}
	
	@RequestMappingName(value = "跳转到添加页面")
	@RequestMapping(value = "/promech", method = RequestMethod.GET)
	public String promech(Model model,HttpServletRequest request,HttpServletResponse response) throws IOException {
		Map<String, Object> searchParams = new HashMap<String,Object>();
		User currentUser = (User)request.getSession().getAttribute("loginUser");

		//项目管理
		if(currentUser.getRoleId()!=null && currentUser.getRoleId().equals(RoleStatus.ROLE_8.getRoleId()+"")){
			searchParams.put("proId", currentUser.getProjectID());
		}
		
		/*java.util.List<Project> list = sysProjectMapper.findAll(searchParams);
		model.addAttribute("project", list);*/
		
		User user = (User)request.getSession().getAttribute("loginUser");
		model.addAttribute("user", user);	
		
		return "/report/promech";
	}
}
